import bsddb
import sys

if len(sys.argv) > 1:
    if sys.argv[2] == 'all' :
        db = bsddb.btopen(sys.argv[1],'r')
        for k in db.keys():
            print k,db[k]
        db.close()
    else:
        db = bsddb.btopen(sys.argv[1],'r')
        if db.has_key(sys.argv[2]) :
            print db[sys.argv[2]]
        db.close()
else:
    print 'ERROR: Please run as \'python viewdb.py [db name] [key]\''
